fix(dev): await worker shutdown before replacing it - #4506
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe dev server coordinates worker shutdown during close and reload. It waits for worker exit, handles timeout and send failures, and suppresses recovery behavior for intentional worker closure. ChangesWorker shutdown coordination
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
src/dev/server.ts (1)
211-243: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftExtract worker lifecycle coordination.
Move the shutdown state and shutdown protocol into an internal module such as
src/dev/_worker-lifecycle.ts. This file already exceeds 200 lines, and this change adds a separate lifecycle unit.As per coding guidelines, “Split logic across files; avoid long single-file modules (>200 LoC).”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/dev/server.ts` around lines 211 - 243, Extract the worker shutdown coordination logic from the server.ts file into a new internal module such as src/dev/_worker-lifecycle.ts. Move the `#shutdownWorker` method, the `#shuttingDown` state field, and related shutdown protocol constants like SHUTDOWN_TIMEOUT into the new module. Create a class or exported functions in the new module that encapsulate this lifecycle management, then update the server.ts file to use the extracted module, removing the original `#shutdownWorker` method and `#shuttingDown` field while delegating to the new module.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/dev/server.ts`:
- Around line 235-237: Update the catch block around the shutdown message
delivery to capture the send error and issue a warning containing the shutdown
operation context and error message, then continue calling done() as before.
- Line 155: Update close() before the await this.#shutdownWorker() call to set a
permanent closing state, reject both new and already queued reload() operations,
and await any active reload represented by `#reloadPromise` before invoking
`#manager.close`(). Ensure reload cannot call `#manager.reload` after closing
begins, while preserving the existing shutdown and watcher-close sequence.
- Around line 82-84: Update the shutdown flow in `#shutdownWorker`() and local
close() so RunnerManager cleanup occurs before `#shuttingDown` is cleared, or keep
that flag set through manager.close(). Ensure registered onClose listeners
observe the intentional-shutdown state and do not call reload(), while
preserving listener cleanup ordering.
---
Nitpick comments:
In `@src/dev/server.ts`:
- Around line 211-243: Extract the worker shutdown coordination logic from the
server.ts file into a new internal module such as src/dev/_worker-lifecycle.ts.
Move the `#shutdownWorker` method, the `#shuttingDown` state field, and related
shutdown protocol constants like SHUTDOWN_TIMEOUT into the new module. Create a
class or exported functions in the new module that encapsulate this lifecycle
management, then update the server.ts file to use the extracted module, removing
the original `#shutdownWorker` method and `#shuttingDown` field while delegating to
the new module.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 203bb772-0c7f-4261-a187-31c373a3b410
📒 Files selected for processing (1)
src/dev/server.ts
🔗 Linked issue
nuxt/nuxt#32928
related: #4088
partly resolve #2735
❓ Type of change
📚 Description
we currently don't await when shutting down a worker, meaning tasks or plugins shutdown can overlap with new startup (e.g. database connection). we've implemented waiting (+ timeout) in nuxt/cli for the nuxt dev server (nuxt/cli#1424) but I thought we should probably do the same for nitro workers.
let me know if you don't think this is desired behaviour, or if you want to move it to
env-runnerinstead 🙏📝 Checklist